package com.lxy.demo.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lxy.demo.dao.InvitationMapper;
import com.lxy.demo.dao.ReplyDetailMapper;
import com.lxy.demo.entity.ReplyDetail;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class ReplyDetailServiceImpl extends ServiceImpl<ReplyDetailMapper,ReplyDetail> implements ReplyDetailService {

    @Autowired(required = false)
    private ReplyDetailMapper replyDetailMapper;

    @Autowired(required = false)
    private InvitationMapper invitationMapper;

    @Override
    public PageInfo selectReply(Integer id, Integer pageNum) {
        PageHelper.startPage(pageNum, 3);
        List<ReplyDetail> list = replyDetailMapper.selectReply(id);
        PageInfo pageInfo = new PageInfo(list);
        return pageInfo;
    }

//    @Override
//    public boolean addReply(ReplyDetail replyDetail) {
//        return replyDetailMapper.addSelective(replyDetail) > 0;
//    }

    public boolean delRep(Integer id) {
        return replyDetailMapper.delRep(id) > 0;
    }

    public boolean delInv(Integer id) {
        if (selectInv(id)) {
            if (delRep(id) && (invitationMapper.delInv(id) > 0)) return true;
        }
        else {
            if (invitationMapper.delInv(id) > 0) return true;
        }
        return false;
    }

    public boolean selectInv(Integer id){
        return replyDetailMapper.findRep(id).size() > 0;
    }
}
